// 1.引入
import vueRouter from 'vue-router'
import Vue from 'vue'

const Home = () => import('views/home/Home')
const Cate = () => import('views/cate/Cate')
const Profile = () => import('views/profile/Profile')
const Shopcart = () => import('views/shopcart/Shopcart')
const Detail = () => import('views/detail/Detail')
// 2. 安装插件
Vue.use(vueRouter)
// 创建路由对象
const routes = [
	{
		path: '/',
		redirect: '/home'
	},
	{
		path: '/home',
		component: Home,
		meta: {
			title: '首页'
		}
	},
	{
		path: '/cart',
		component: Shopcart,
		meta: {
			title: '购物车'
		}
	},
	{
		path: '/cate',
		component: Cate,
		meta: {
			title: '分类'
		}
	},
	{
		path: '/profile',
		component: Profile,
		meta: {
			title: '我的'
		}
	},
	{
		path: '/detail/:iid',
		component: Detail,
		meta: {
			title: "详情页"
		}
	}
]

const router = new vueRouter({
	routes,
	mode: 'history'
})

router.beforeEach((to, from, next) => {
	window.document.title = to.matched[0].meta.title
	next()
})
// 导出
export default router